﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace GoogleCalendarView
{
	/// <summary>
	/// Interaction logic for UserEntryPanel.xaml
	/// </summary>
	public partial class UserEntryPanel : Window
	{
		/// <summary>
		/// Constructor. Inits the Panel
		/// </summary>
		public UserEntryPanel()
		{
			InitializeComponent();
		}

		#region Command Handlers

		/// <summary>
		/// Saves the user in the DB and closes the Window.
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void SaveCommandHandler(object sender, ExecutedRoutedEventArgs e)
		{
			Window parentWindow = this.Owner;
			if (parentWindow is MainView)
			{
				((MainView)parentWindow).SaveNewUser(accountNameBox.Text, userNameBox.Text, passwordBox.Text);
			}
			this.Close();
		}

		/// <summary>
		/// Closes the Panel. E.g. when pressing on the Cancel - button
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void CloseCommandHandler(object sender, ExecutedRoutedEventArgs e)
		{
			this.Close();
		}

		#endregion
	}
}
